
#ifndef LIBCR_FCONTEXT_H
#define LIBCR_FCONTEXT_H

#include <unistd.h>
#include <cstddef>
#include <cstdint>

struct stack {
  void *base;
  void *limit;

  stack() : base(0), limit(0) {}
};

struct fp {
  uint32_t fc_freg[2];

  fp() : fc_freg() {}
};

struct fcontext_t {
  uint64_t fc_greg[8];
  stack fc_stack;
  fp fc_fp;

  fcontext_t() : fc_greg(), fc_stack(), fc_fp() {}
};

extern "C" void *align_stack(void *vp);
extern "C" intptr_t jump_fcontext(fcontext_t *ofc, fcontext_t const *nfc,
                                  intptr_t vp, bool preserve_fpu = true);
extern "C" void make_fcontext(fcontext_t *fc, void (*fn)(intptr_t));

#endif
